﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agresso.Interface.Layer.Service;
using System.Collections;
using System.Configuration;
using Agresso.Interface.Layer.Domain;
using System.IO;
using System.Globalization;

namespace Agresso.Interface.Layer.GUI
{
    class Program
    {
        static void Main(string[] args)
        {
            //InvoiceService isvc = new InvoiceService();
            //isvc.ImportDataFromXml();

           // KofaxInvoiceService kfs = new KofaxInvoiceService();
           // kfs.ExecuteInterface();
            //kfs.ImportDataFromXml();

            //MaxPostInvoiceService msc = new MaxPostInvoiceService();
            //msc.ImportDataFromXml();
           // msc.ExecuteInterface();

           // VesselService vslSvc = new VesselService();
           // vslSvc.UpdateVesselIDLLOYDNumber();
           // vslSvc.FindVesselByName("Anangel Sun", "10579", "PCL (SHIPPING) PTE LTD");

          //  CrewPayrollService cps = new CrewPayrollService();
            //cps.ExecuteCrewPayrollStagingInterface();
            //cps.ExecuteCrewPayrollInterface();
            //StatementService stmtSVC = new StatementService();
            // stmtSVC.ImportAllDataSoftmarToMiddleLayer(0,"PACC UK/648");
            // stmtSVC.ImportAllDataSoftmarToMiddleLayer(0,"PACC UK/650");
            //stmtSVC.ImportAllDataSoftmarToMiddleLayer(0,"PACC UK/680");
            //stmtSVC.ImportAllDataSoftmarToMiddleLayer(1, "PCLS/14295");
            //stmtSVC.ImportAllDataSoftmarToMiddleLayer(1, "PCLS/14687");
            //stmtSVC.ImportAllDataSoftmarToMiddleLayer(1, "PCLS/14084");
            //stmtSVC.ImportAllDataSoftmarToMiddleLayer(1, "PCLS/13574");
            //stmtSVC.ImportAllDataSoftmarToMiddleLayer(1, "PCLS/14941");

            //stmtSVC.ExecuteStatementInterface();

            //BunkerGRNService svc = new BunkerGRNService();
        //    svc.ImportAllDataSoftmarToMiddleLayer(1141);
       //     svc.ImportAllDataSoftmarToMiddleLayer(1238);
      //      svc.ImportAllDataSoftmarToMiddleLayer(1237);
            //svc.ImportAllAgressoPOToMiddleLayer();
           //svc.ExecuteBunkerGRNByPO();


            //BunkerPOService poService = new BunkerPOService();
           // poService.ExecuteBunkerProcurementPO();
           // poService.ImportAllDataSoftmarToMiddleLayer(1141);
          //   poService.ImportAllDataSoftmarToMiddleLayer(1238);
          //   poService.ImportAllDataSoftmarToMiddleLayer(1237);

            
            


           //poService.ExecuteBunkerProcurementPO();

          //  BunkerInventoryService scv = new BunkerInventoryService();
            //scv.ImportAllDataSoftmarToMiddleLayerBODandBOR();
            //scv.UpdateEndVoyageDate();
            //scv.ImportAllDataSoftmarToMiddleLayer();
            //scv.ExecuteInterfaceIRBunkerOnReDelivery();
          //  scv.ExecuteInterfaceIWBunkerOnDelivery();

            //StatementService svc = new StatementService();
           // svc.ExecuteStatementInterface();
            //svc.ImportAllDataSoftmarToMiddleLayer(0);
            //svc.ImportAllDataSoftmarToMiddleLayer(1);

           // EmailService.SendByLocalServer("test interface", "test test", new string[1] { "widagdo.baskoro2@ddw-paxocean.com" });

            //EmailService.SendByDEVServer("test interface", "test test", "widagdo.baskoro2@ddw-paxocean.com");

            // FreightCommisionInvoiceService pp = new FreightCommisionInvoiceService();
            // pp.Execute();
            //BunkerPOService stv = new BunkerPOService();
            //stv.ExecuteBunkerProcurementPO();
           //// VoyageMasterService vms = new VoyageMasterService();
          ///  vms.ImportAllDataSoftmarToMiddleLayer();

           //CommissionInvoiceService commissionInvoiceService = new CommissionInvoiceService();
          // commissionInvoiceService.ExecuteFreightHireInvoiceCargoReletChargeCreditOUT();
          //commissionInvoiceService.ExecuteCommissionInvoiceTCReletType(); //supplier
           //commissionInvoiceService.ExecuteCommissionInvoiceTCReletTypeChargeDebit(); // customer
         //  commissionInvoiceService.ExecuteFreightHireInvoiceCargoReletChargeDebitIN(); //customer
           //commissionInvoiceService.ExecuteFreightHireInvoiceCargoReletChargeCreditOUT(); //supplier
           //commissionInvoiceService.ExecuteFreightHireInvoiceCargoReletCommissionCreditIN(); //supplier
           //commissionInvoiceService.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_COMMISSION_INVOICE_TCRELET);
           //com.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_FREIGHT_HIRE_INVOICE);
            //com.ExecuteCommissionInvoiceTCReletType();
           //com.ExecuteCommissionInvoiceTCReletTypeChargeDebit();
          // com.ExecuteFreightHireInvoiceCargoReletChargeDebitIN();
          // com.ExecuteFreightHireInvoiceCargoReletChargeCreditOUT();
          // com.ExecuteFreightHireInvoiceCargoReletCommissionCreditIN();
           
           //com.ImportAllDataSoftmarToMiddleLayerProforma();
           //com.SetTestDateProforma(new DateTime(2013, 9, 30));
           //com.ExecuteInvoiceProformaCommissionCredit();
           //com.ExecuteInvoiceProformaChargeCredit();
           //com.ExecuteInvoiceProformaChargeDebit();
            //com.ImportAllDataSoftmarToMiddleLayerProforma();
          // com.ExecuteCommissionInvoiceTCReletType();
        //   com.ExecuteFreightHireInvoice();
        //  com.ExecuteInvoiceProforma();
           // WinSDSService svc = new WinSDSService();
           // svc.ImportSupplierDataFromAgressoToDMZ();

           //StatementService svc = new StatementService();
           //svc.ImportAllDataSoftmarToMiddleLayer(1);
           //svc.ImportAllDataSoftmarToMiddleLayer(1);
          /// svc.ExecuteStatementInterface();
           //com.ExecuteInvoiceProforma();
           //com.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_COMMISSION_INVOICE_TCRELET);
           //com.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_FREIGHT_HIRE_INVOICE);
           //com.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_PROFORMA);
           // com.ExecuteInvoiceProforma();
           // VoyageMasterService vmsc = new VoyageMasterService();
           // vmsc.ExecuteVoyageMasterInterface();

          //  BunkerInventoryService bdc = new BunkerInventoryService();
          //bdc.ImportAllDataSoftmarToMiddleLayerBODandBOR();
           //bdc.ExecuteInterfaceIW();
           // CommissionTest();
            //ImportVoyageToProduction();
           // CommissionInvoiceService com = new CommissionInvoiceService();
           // com.ExecuteInvoiceProforma();
             //com.ExecuteFreightHireInvoice();
             //com.ExecuteCommissionInvoiceTCReletType();

          // WinSDSService wsds = new WinSDSService();
           //wsds.UpdateAlgbatchinputRemark();
          // wsds.UpdatePOID();
           //wsds.UpdatePOApprovedDate();
           // wsds.ExecuteInterfaceAllPOData();
  //          wsds.UpdatePOApprovedDate();


         //  BunkerPOService pov = new BunkerPOService();
         // pov.UpdateEstQtyMax();
           //pov.ExecuteBunkerProcurementPO();  

            //BunkerGRNService grnsvc = new BunkerGRNService();
            //grnsvc.ImportAllDataSoftmarToMiddleLayer();
            //grnsvc.ExecuteBunkerGRNByPO();

            DADesk_PDA_Service svc = new DADesk_PDA_Service();
            svc.ImportDataFromXml();
          //  svc.ExecuteInterfaceFDA();
          //  svc.ExecuteInterfacePDA();
            //DADESKTest();
            //WinSDSTest();
           // vesselmappingtest();
            //DateTesting();
          

           //WinSDSService poscv = new WinSDSService();
          // poscv.ExecuteInterfaceAllPOData();
            //poscv.ImportAllDataSoftmarToMiddleLayer();

         //   VoyageMasterService vms = new VoyageMasterService();
            //vms.ImportAllDataSoftmarToMiddleLayer();
        //  vms.ExecuteVoyageMasterInterface();

           // StatementService p = new StatementService();
           //p.ImportAllDataSoftmarToMiddleLayer();
          //  p.ExecuteStatementInterface();

            //p.ImportAllDataSoftmarToMiddleLayer();
            //p.ImportDataSoftmarToMiddleLayer(DateTime.Today.AddDays(-1), SoftmarType.SOFTMAR_FREIGHT_HIRE_INVOICE);
            //p.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_FREIGHT_HIRE_INVOICE);
            //p.ExecuteCommissionInvoiceTCReletType(  );
            //p.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_COMMISSION_INVOICE_VOYAGE_CARGO_RELET);
            //p.ImportDataSoftmarToMiddleLayer(DateTime.Today.AddDays(-1), SoftmarType.SOFTMAR_COMMISSION_INVOICE_VOYAGE_CARGO_RELET);
            //p.ExecuteCommissionInvoiceVCReletType();
            //p.ExecuteFreightHireInvoice();
            //p.StoreDataSoftmarToMiddleLayer();
            //p.ImportDataSoftmarToMiddleLayer(DateTime.Today.AddDays(-1));
           // ChargeTypeAccountMappingService p = new ChargeTypeAccountMappingService();
            //p.IsValidChargeTypeAccountMapping("Hire");

          //  BunkerPOService poSevice = new BunkerPOService();
           // BunkerInventoryService svc = new BunkerInventoryService();
          //  svc.ImportAllDataSoftmarToMiddleLayerTotalConsumption();
           // //svc.ImportAllDataSoftmarToMiddleLayer();
           // //svc.ExecuteInterface();
           // ResponsibleUserService rus = new ResponsibleUserService();
           //// poSevice.ImportAllDataSoftmarToMiddleLayer();
           //// svc.ExecuteBunkerProcurementPO();
           // IList pos = svc.GetAllPendingBunkerInventory();
           // foreach (BunkerInventory po in pos)
           // {
           //     if (po.last_updated_by != "")
           //         rus.GetResponsibleUserByName(po.operated_by);
           // }

            //BunkerGRNService grnSevice = new BunkerGRNService();
            //grnSevice.ImportAllDataSoftmarToMiddleLayer();
            //grnSevice.ExecuteBunkerGRN();

            //WinSDSService svc = new WinSDSService();
            //svc.ImportSupplierDataFromAgressoToDMZ();
           // svc.ExecuteInterfaceAllPOData();
            //svc.ExecuteInterfaceAllGRNData();
            // WinSDSTest();

          //  ProfitCentreService p = new ProfitCentreService();
           // IList profitcentres = p.GetAllProfitCentreMapping();
           // foreach (ProfitCentre c in profitcentres)
           // {
          //      p.GetProfitCentreMapping(c.full_name);
           // }

            //VesselService vservice = new VesselService();
           //vservice.FindVesselByName(""
           //IList ves =  vservice.GetAllVesselMapping();
           //foreach (Vessel v in ves)
           //{
           //    if(v.agr_dim_value.Trim() == "")
           //    vservice.FindVesselByName(v.vessel_name);
           //}

            //SupplierCustomerService svc = new SupplierCustomerService();
            //asuheaderService ass = new asuheaderService();
            //acuheaderService acs = new acuheaderService();
            //IList csm = svc.GetAllSupplierCustomerMapping();
            //foreach (SupplierCustomer cs in csm)
            //{
            //    //if (cs.agr_supp_apar_id.Trim() != "")
            //    //{
            //    //    asuheader ash = ass.GetSupplierByCode(cs.agr_supp_apar_id);
            //    //    if (ash != null)
            //    //    {
            //    //        cs.apar_gr_id = ash.apar_gr_id;
            //    //        svc.UpdateSupplierCustomerMapping(cs);
            //    //    }
            //    //}
            //    if (cs.agr_cust_apar_id.Trim() != "")
            //    {
            //        acuheader ach = acs.GetCustomerByCode(cs.agr_cust_apar_id);
            //        if (ach != null)
            //        {
            //            cs.cus_apar_gr_id = ach.apar_gr_id;
            //            svc.UpdateSupplierCustomerMapping(cs);
            //        }
            //    }
            //}
           //IList vend = svc.GetAllSupplierCustomerMapping();
           //foreach (SupplierCustomer ven in vend)
           //{
           //    svc.GetSupplierMapping(ven.short_name);
           //}

           // CommissionInvoiceService svc = new CommissionInvoiceService();
           // svc.ExecuteInvoiceProforma();
          //  svc.ImportAllDataSoftmarToMiddleLayerProforma();
           //svc.ExecuteInvoiceProforma();
          // svc.ExecuteCommissionInvoiceTCReletType();
         //  svc.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_COMMISSION_INVOICE_TCRELET);
           // svc.ExecuteFreightHireInvoice();




            //ChargeTypeAccountMappingService csv = new ChargeTypeAccountMappingService();
            //StreamReader sr = new StreamReader(@"C:\log\MapTC.csv");
            //while (!sr.EndOfStream)
            //{
            //    String lines = sr.ReadLine();
            //    string[] line = lines.Split(',');
            //    ChargeTypeAccountMapping cs = csv.GetChargeTypeAccountMapping(line[0].Trim());
            //    if (cs != null)
            //    {
            //        cs.tcrelet_account = line[1];
            //        cs.tcrelet_account_name = line[2];
            //        cs.tcrelet_tax_account = line[3];
            //        cs.tcrelet_tax_account_singapore = line[4];

            //        cs.vcrelet_account = line[5];
            //        cs.vcrelet_account_name = line[6];
            //        cs.vcrelet_tax_account = line[7];
            //        cs.vcrelet_tax_account_singapore = line[8];

            //        csv.UpdateChargeTypeAccountMapping(cs);
            //    }
            //}

            //BunkerInventoryManagerMappingService csv = new BunkerInventoryManagerMappingService();
            //agldimvalueService csvp = new agldimvalueService();
            //StreamReader sr = new StreamReader(@"C:\Project\Temp\bunkerinventorymanager.csv");
            //while (!sr.EndOfStream)
            //{
            //    String lines = sr.ReadLine();
            //    string[] line = lines.Split(',');
            //    BunkerInventoryManagerMapping cs = csv.SearchByDimValue(line[0].Trim());
            //    if (cs != null)
            //    {
            //        agldimvalue map = csvp.GetAglDimValueProfitCentreByDimValue(line[1].Trim());
            //        cs.rel_value_map = map.rel_value;
            //        cs.dim_value_map = map.dim_value;
            //        cs.client_map = map.client;
            //        cs.description_map = map.description;

            //        csv.Update(cs);
            //    }
            //}
           
            

            //BunkerPOService posvc = new BunkerPOService();
            //posvc.ImportAllDataSoftmarToMiddleLayer();
            //posvc.ExecuteBunkerProcurementPO();

            //asuheaderService asv = new asuheaderService();
            //StreamReader sr = new StreamReader(@"C:\Project\Temp\supplier.txt");
            //FileStream fs = File.Create(@"C:\Project\Temp\result.txt");
            //fs.Close();
            //StreamWriter sw = File.AppendText(@"C:\Project\Temp\result.txt");
            //while (!sr.EndOfStream)
            //{
            //    String lines = sr.ReadLine();
            //    string[] line = lines.Trim().Split(' ');
            //    asuheader asu = asv.GetSupplierByNameClienS1Like(line[0]);
            //    if (asu == null)
            //    { asu = new asuheader(); }
            //    sw.WriteLine(lines + ";" + asu.apar_id + ";" + asu.apar_name + ";" + asu.client + ";" + asu.apar_gr_id);
            //}
            //sw.Close();

            //acuheaderService csv = new acuheaderService();
            //StreamReader sr = new StreamReader(@"C:\Project\Temp\customer.txt");
            //FileStream fs = File.Create(@"C:\Project\Temp\resultcustomer.txt");
            //fs.Close();
            //StreamWriter sw = File.AppendText(@"C:\Project\Temp\resultcustomer.txt");
            //while (!sr.EndOfStream)
            //{
            //    String lines = sr.ReadLine();
            //    string[] line = lines.Trim().Split(' ');
            //    acuheader asu = csv.GetCustomerByNameClienS1Like(lines);
            //    if (asu == null)
            //    { asu = new acuheader(); }
            //    sw.WriteLine(lines + ";" + asu.apar_id + ";" + asu.apar_name + ";" + asu.client + ";" + asu.apar_gr_id);
            //}
            //sw.Close();

            //acuheaderService csv = new acuheaderService();
            //SupplierCustomerService cuss = new SupplierCustomerService();

            //StreamReader sr = new StreamReader(@"C:\Project\Temp\customerMap.txt");
            //while (!sr.EndOfStream)
            //{
            //    String lines = sr.ReadLine();
            //    string[] line = lines.Trim().Split(';');
            //    SupplierCustomer custSoft = cuss.GetCustomerMapping(line[0]);
            //    if (custSoft == null)
            //    {
 
            //    }
            //    acuheader acu = csv.GetCustomerByCode(line[1]);
            //    if (acu != null)
            //    {
            //        custSoft.agr_cust_apar_id = acu.apar_id;
            //        custSoft.agr_cust_apar_name = acu.apar_name;
            //        custSoft.cust_client = acu.client;
            //        cuss.UpdateSupplierCustomerMapping(custSoft);
            //    }
            //    else
            //    {
            //    }
            //}

            //asuheaderService csv = new asuheaderService();
            //SupplierCustomerService cuss = new SupplierCustomerService();
            //StreamReader sr = new StreamReader(@"C:\Project\Temp\supplierMap.txt");
            //while (!sr.EndOfStream)
            //{
            //    String lines = sr.ReadLine();
            //    string[] line = lines.Trim().Split(';');
            //    SupplierCustomer supSoft = cuss.GetSupplierMapping(line[0]);
            //    if (supSoft == null)
            //    {

            //    }
            //    asuheader asu = csv.GetSupplierByCode(line[1]);
            //    if (asu != null)
            //    {
            //        supSoft.agr_supp_apar_id = asu.apar_id;
            //        supSoft.agr_supp_apar_name = asu.apar_name;
            //        supSoft.client = asu.client;
            //        cuss.UpdateSupplierCustomerMapping(supSoft);
            //    }
            //    else
            //    {
            //    }
            //}


           // asuheaderService csv = new asuheaderService();
            //VesselService svc = new VesselService();
            //StreamReader sr = new StreamReader(@"C:\Project\Temp\vesselmaster.txt");
            //while (!sr.EndOfStream)
            //{
            //    String vesselname = sr.ReadLine().Trim();
            //    svc.FindVesselByName(vesselname);
            //}

            //StreamReader sr = new StreamReader(@"C:\Project\Temp\softmaruser.txt");
            //ResponsibleUserService svc = new ResponsibleUserService();
            //while (!sr.EndOfStream)
            //{
            //    String user = sr.ReadLine();
            //    svc.GetResponsibleUserByName(user.Trim());
            //}
        }

        private static void ImportVoyageToProduction()
        {
            
            //ChargeTypeAccountMappingService csv = new ChargeTypeAccountMappingService();
            agldimvalueService aglService = new agldimvalueService();
            VesselService vesselService = new VesselService();
            ProfitCentreService pcService = new ProfitCentreService();
            VoyageMasterService vmService = new VoyageMasterService();
            ud_voyageimp_Service ud_voyageimp_Svc = new ud_voyageimp_Service();
           // vmService.ImportAllDataSoftmarToMiddleLayer();

            StreamReader sr = new StreamReader(@"C:\Project\Temp\VoyageProduction.csv");
            int i = 0;
            IList vesselNotfound = new ArrayList();
            while (!sr.EndOfStream)
            {
                String lines = sr.ReadLine();
                string[] line = lines.Split(',');
                string voyageCode = line[0];
                string vesselName = line[1];
                string client = line[2];
                string voyage = line[3];
                string vesseldimval = line[4];

                //agresso checkin --- OK
                agldimvalue vesselagl = aglService.GetAglDimValueVesselByDimValueAndClient(vesseldimval, client);
                agldimvalue costcentre = null;
                agldimvalue profitcentre = null;
                ProfitCentre profitCEntreMap = null;
                if (vesselagl == null)
                {
                    StreamWriter sw = File.AppendText(@"C:\Project\Temp\VesselDimValNotFoundInAgresso.csv");
                    //sw.WriteLine(DateTime.Now.ToString() + " " + lines);
                    sw.WriteLine(lines);
                    sw.Close();
                }
               
                else
                {
                    costcentre = aglService.GetAglDimValueCostCentreByDimVal(vesselagl.rel_value);
                    if (costcentre == null)
                    {

                    }
                    else
                    {
                        profitcentre  = aglService.GetAglDimValueProfitCentreByDimValue(costcentre.rel_value);
                        if (profitcentre == null)
                        {

                        }
                        else
                        {
                            profitCEntreMap = pcService.GetProfitCentreByDimValue(profitcentre.dim_value);
                        }
                    }
                }

                
                Vessel vMapList = vesselService.GetAllVesselMappingByDimValueAndClient(vesseldimval,client.Trim());
                if (vMapList == null)
                {
                    vesselNotfound.Add(vesselName);
                    StreamWriter sw = File.AppendText(@"C:\Project\Temp\VoyageProductionNotFound.csv");
                    sw.WriteLine(DateTime.Now.ToString() + " - " + lines);
                    //sw.WriteLine(lines);
                    sw.Close();
                }
                else
                {
                    IList voyageMasterList = vmService.GetVoyageMasterByVesselNameAndVoyageAndProfitCentre(vMapList.vessel_name.Trim(), voyage, profitCEntreMap.full_name.Trim());
                    if (voyageMasterList.Count == 0)
                    {
                        StreamWriter sw = File.AppendText(@"C:\Project\Temp\VoyageProductionNotFoundInSoftmar.csv");
                         sw.WriteLine(DateTime.Now.ToString() + " - " + lines);
                       // sw.WriteLine(lines);
                        sw.Close();
                    }
                    else
                    {
                        if (vesselagl != null && costcentre != null && profitcentre != null)
                        {
                            VoyageMaster vm =  (VoyageMaster)voyageMasterList[0];
                            ud_voyageimp udv = new ud_voyageimp(profitcentre.client, vesseldimval, vm);
                            //ud_voyageimp_Svc.Insert(udv);
                           // vmService.UpdateFlag(vm.i_voyage_master_id, udv.recid.ToString(), "1");

                            StreamWriter sw = File.AppendText(@"C:\Project\Temp\VoyageProductionFoundInSoftmar.csv");
                            sw.WriteLine(DateTime.Now.ToString() + " - " + lines);
                            //sw.WriteLine(lines);
                            sw.Close();
                        }
                    }
                }
                i++;
            }
        }

        private static void ProformaTest()
        {
            CommissionInvoiceService com = new CommissionInvoiceService();
            // com.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_PROFORMA);
            IList p = com.GetAllProforma();
            IList Exception = new ArrayList();
            foreach (InvoiceProforma ip in p)
            {
                CommissionInvoice ci = null;
                IList items = com.GetProformaItem(ip);
                if (ci == null)
                {
                    ci = (CommissionInvoice)items[0];
                    ci.Header = (CommissionInvoice)items[0];
                    ci.Items = items;
                }
                if (ip.invoice_type == "Charge Credit")
                {
                    decimal total = 0;
                    if (items.Count == 1)
                        total = ip.invoice_amount;
                    else
                        foreach (CommissionInvoice i in items)
                        {
                            total += i.charge_amount;
                            total -= i.charge_addr_comm;
                            total -= i.charge_collect_comm;
                        }
                    if (total != ip.invoice_amount)
                        Exception.Add("Charge Credit " + ip.vessel_name + " " + ip.voyage_no + " " + ip.invoice_amount);
                }
                if (ip.invoice_type == "Charge Debit")
                {
                    decimal total = 0;
                    if (items.Count == 1)
                        total = ip.invoice_amount;
                    else
                        foreach (CommissionInvoice i in items)
                        {
                            total += i.charge_amount;
                            //total -= i.charge_collect_comm;
                            total -= i.charge_addr_comm;
                            total -= i.charge_non_collect_comm;
                        }
                    if (total != ip.invoice_amount)
                        Exception.Add("Charge Debit " + ip.vessel_name + " " + ip.voyage_no + " " + ip.invoice_amount);
                }
                if (ip.invoice_type == "Commission Credit")
                {
                    decimal total = 0;
                    if (items.Count == 1)
                        total = ip.invoice_amount;
                    else
                    {
                        foreach (CommissionInvoice i in items)
                        {
                            com.GetCollectCommission(i);
                        }
                        total = ci.GetTotalCollectCommission();
                        if (total != ip.invoice_amount)
                            total = ci.GetTotalCollectCommission1();
                        if (total != ip.invoice_amount)
                            total = ci.GetTotalCollectCommission2();
                        if (total != ip.invoice_amount)
                            total = ci.GetTotalCollectCommission3();
                        if (total != ip.invoice_amount)
                            total = ci.GetTotalCollectCommission4();
                        if (total != ip.invoice_amount)
                            total = ci.GetTotalChargeAddressCommission();
                    }
                    if (total != ip.invoice_amount)
                        Exception.Add("Commission Credit " + ip.vessel_name + " " + ip.voyage_no + " " + ip.invoice_amount);
                }
            }
        }
        private static void CommissionTest()
        {
            CommissionInvoiceService com = new CommissionInvoiceService();
            // com.ImportAllDataSoftmarToMiddleLayer(SoftmarType.SOFTMAR_PROFORMA);
            IList p = com.GetAllCommission();
            IList Exception = new ArrayList();
            foreach (string ivc in p)
            {
                CommissionInvoice ci = null;
                IList items = com.GetCommissionItem(ivc);
                if (ci == null)
                {
                    ci = (CommissionInvoice)items[0];
                    ci.Header = (CommissionInvoice)items[0];
                    ci.Items = items;
                }
                if (ci.invoice_type == "Charge Credit")
                {
                    decimal total = 0;
                    if (items.Count == 1)
                        total = ci.invoice_amount;
                    else
                        foreach (CommissionInvoice i in items)
                        {
                            total += i.charge_amount;
                            total -= i.charge_addr_comm;
                            total -= i.charge_collect_comm;
                        }
                    if (total != ci.invoice_amount)
                        Exception.Add("Charge Credit " + ci.vessel_name + " " + ci.voyage_no + " " + ci.invoice_amount);
                }
                if (ci.invoice_type == "Charge Debit")
                {
                    decimal total = 0;
                    if (items.Count == 1)
                        total = ci.invoice_amount;
                    else
                        foreach (CommissionInvoice i in items)
                        {
                            total += i.charge_amount;
                            //total -= i.charge_collect_comm;
                            total -= i.charge_addr_comm;
                            total -= i.charge_non_collect_comm;
                        }
                    if (total != ci.invoice_amount)
                        Exception.Add("Charge Debit " + ci.vessel_name + " " + ci.voyage_no + " " + ci.invoice_amount);
                }
                if (ci.invoice_type == "Commission Credit")
                {
                    decimal total = 0;
                    if (items.Count == 1)
                        total = ci.invoice_amount;
                    else
                    {
                        foreach (CommissionInvoice i in items)
                        {
                            com.GetCollectCommission(i);
                        }
                        total = ci.GetTotalCollectCommission();
                        if (total != ci.invoice_amount)
                            total = ci.GetTotalCollectCommission1();
                        if (total != ci.invoice_amount)
                            total = ci.GetTotalCollectCommission2();
                        if (total != ci.invoice_amount)
                            total = ci.GetTotalCollectCommission3();
                        if (total != ci.invoice_amount)
                            total = ci.GetTotalCollectCommission4();
                        if (total != ci.invoice_amount)
                            total = ci.GetTotalChargeAddressCommission();
                    }
                    if (total != ci.invoice_amount)
                        Exception.Add("Commission Credit " + ci.vessel_name + " " + ci.voyage_no + " " + ci.invoice_amount);
                }
            }
        }

        private static void vesselmappingtest()
        {
            VesselService vs = new VesselService();
            IList vessel = vs.GetAllVesselMapping();
          //  bool valid = vs.IsValidVesselMapping("Orient Singapore");
            foreach (Vessel v in vessel)
            {
                vs.FindVesselByName(v.vessel_name,"");
            }
        }

        private static void WinSDSTest()
        {
            WinSDSService svc = new WinSDSService();
            IList objects= svc.RetrieveAttachmentDataList();
            string winSDSFolder = ConfigurationManager.AppSettings["WinSDSAttachmentFolder"];
            foreach (jPOAttachments attachment in objects)
            {
                attachment.WriteFile(winSDSFolder);
            }
        }

        private static void DADESKInterfaceTest()
        {
            DADesk_PDA_Service svc = new DADesk_PDA_Service();
            svc.ImportDataFromXml();
            svc.ExecuteInterfaceFDA();
        }
        
        public static void DateTesting()
        {
            // Create an array of all supported standard date and time format specifiers. 
            string[] formats = {"d", "D", "f", "F", "g", "G", "m", "o", "r", 
                          "s", "t", "T", "u", "U", "Y"};
            // Create an array of four cultures.                                 
            CultureInfo[] cultures = {CultureInfo.CreateSpecificCulture("de-DE"), 
                                CultureInfo.CreateSpecificCulture("en-US"), 
                                CultureInfo.CreateSpecificCulture("es-ES"), 
                                CultureInfo.CreateSpecificCulture("fr-FR")};
            // Define date to be displayed.
            DateTime dateToDisplay = new DateTime(2008, 10, 1, 17, 4, 32);

            // Iterate each standard format specifier. 
            foreach (string formatSpecifier in formats)
            {
                foreach (CultureInfo culture in cultures)
                    Console.WriteLine("{0} Format Specifier {1, 10} Culture {2, 40}",
                                      formatSpecifier, culture.Name,
                                      dateToDisplay.ToString(formatSpecifier, culture));
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }
}
